from graph import Graph
from point import Point
class Astart(object):
    def __init__(self, Graph, start_point, end_point):
        self.Graph = Graph
        self.path = []
        self.start_point = start_point
        self.end_point = end_point
        self.g = { }
        self.parents = { }
        self.h = {}
        self.f = {}
    def bound(current_point):
        if (current_point.x >=0 and current_point.x < Graph.m) and (current_point.y >= 0 and current_point.y < Graph.n):
            return True

        else: return False

    def getNeighbors(current_point):
        neighbors = []
        direction = [(0,1),(0,-1),(1,0),(-1,0)]
        next_point = []
        for (dx,dy) in direction:
            next_point=(current_point.x, current_point.y)
            if(bound(next_point) and (next_point not in Graph.obstacle)):
                neighbors.append(next_point)
        return neightbors

    def path():
        open_set = set()
        close_set = set()
        open_set.add(start_point)
        current_point = start_point
        while len(open_set) != 0:

            if current_point == end_point:
                return True
            else:
                for (m, weight) in get_neighbors(n): #weight
                    if m not in open_set and m not in close_set:
                        open_set.add(m)
                        parents[m] = n
                        g[m] = g[n] + weight
